package com.xtkj.superclub_friendscircle.controller;

import com.xtkj.commons.JsonParse;
import com.xtkj.commons.JsonResult;
import com.xtkj.superclub_entity.entity.friendsCircle.UserLike;
import com.xtkj.superclub_entity.entity.user.User;
import com.xtkj.superclub_friendscircle.annotation.Login;
import com.xtkj.superclub_friendscircle.client.IUserInfoClient;
import com.xtkj.superclub_friendscircle.service.ILikes2RedisService;
import io.goeasy.GoEasy;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 项目名称：superclub
 * 类 名 称：LikeController
 * 类 描 述：TODO
 * 创建时间：2020/1/6 11:23
 * 创 建 人：xiezhiyan
 */
@RestController
@RequestMapping("/like")
public class LikeController {

    @Autowired
    private ILikes2RedisService likes2RedisService;
    @Autowired
    private RabbitTemplate rabbitTemplate;//使用RabbitTemplate,这提供了接收/发送等等方法

    @Login
    @RequestMapping(value = "/friendsCircleFabulous", method = RequestMethod.POST)

    public JsonResult friendsCircleFabulous(HttpServletRequest request, @RequestBody UserLike userLikes) {
        try {
            String token = request.getParameter("token");
            // String userId = TokenUtil.getUserId(token);
            String likesUserId="1";
            //发送队列
            userLikes.setLikesUserId(likesUserId);
            String userLikesstring = JsonParse.obj2String(userLikes);
            StringBuilder builder= new StringBuilder();
            builder.append(userLikesstring).append("-").append(token);
            String str = builder.toString();
            rabbitTemplate.convertAndSend("TestDirectExchange","TestDirectRouting",str);
            return  null;
        } catch (Exception e) {
           e.printStackTrace();
            return JsonResult.error().setCode(500).setMsg("异常错误");
      }
}}